<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 快速排序


    function quickSort(list) {

        if (list.length <= 1) return list;

        var midIndex = Math.floor(list.length / 2);
        var mid = list.splice(midIndex, 1)[0]; // 删除下标为midIndex的元素 并去除

        // console.log(mid, list);

        var leftArr = [];
        var rightArr = [];

        for (var i = 0; i < list.length; i++) {
            var item = list[i];
            if (item <= mid) {
                leftArr.push(item);
            } else {
                rightArr.push(item);
            }
        }
        // console.log(leftArr, mid, rightArr);

        return quickSort(leftArr).concat(mid, quickSort(rightArr));

    }
    var list = [86, 58, 61, 43, 92, 71];
    var result = quickSort(list);
    console.log(result);
    console.log(list);



</script>

</html>